package com.ctbu.yyx.cameracontrol.service;

import com.ctbu.yyx.cameracontrol.domain.User;
import com.ctbu.yyx.cameracontrol.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    public List<User> findAll(){
        return userRepository.findAll();
    }

    public List<User> findByUserNameAndUserPassword(String username, String userpassword){
        return userRepository.findByUserNameAndUserPassword(username,userpassword);
    }

    public List<User> findByUserName(String username){
        return userRepository.findByUserName(username);
    }

    public User findById(Integer id){
        return userRepository.findById(id).orElse(null);
    }

    public User insert(User user){
        userRepository.save(user);
        return user;
    }

    public User update(User user) {
        userRepository.save(user);
        return user;
    }

    public void delete(Integer id) {
        User user = new User();
        user.setId(id);
        userRepository.delete(user);
    }

}
